package lockforredis.timer;

import lockforredis.common.RedisLock;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * 定时器测试分布式锁
 *
 * @author: 顾志杰
 */
@Service
@Slf4j
public class TimerTest {

    @Autowired
    private RedisTemplate redisTemplate;
//    @Scheduled(cron = "0/5 * * * * ?")
    public void sendSms(){
        try(RedisLock redisLock = new RedisLock(redisTemplate,"autoSms",30)) {
            if (redisLock.getLock()){
                log.info("向用户发送短信！");
            }else{
                log.info("我没抢到发送短信！");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
